const Mock = require('mockjs')

const menuList = [
    {
        id: 1,
        name: '用户管理',
        path: '',
        icon: 'iconfont icon-team',
        children: [{ id: 10, name: '用户列表', path: 'user', icon: 'el-icon-user' }]
    },
    {
        id: 2,
        name: '权限管理',
        path: '',
        icon: 'el-icon-menu',
        children: [
            { id: 20, name: '角色列表', path: '', icon: 'el-icon-user' },
            { id: 21, name: '权限列表', path: '', icon: 'el-icon-user' }
        ]
    },
    {
        id: 3,
        name: '商品管理',
        path: '',
        icon: 'el-icon-s-marketing',
        children: [
            { id: 30, name: '商品列表', path: '', icon: 'el-icon-s-marketing' },
            { id: 31, name: '分类参数', path: '', icon: '' },
            { id: 32, name: '商品分类', path: '', icon: '' }
        ]
    },
    {
        id: 4,
        name: '订单管理',
        path: '',
        icon: 'el-icon-s-promotion',
        children: [{ id: 40, name: '订单列表', path: '', icon: '' }]
    },
    {
        id: 5,
        name: '数据统计',
        path: '',
        icon: 'el-icon-s-data',
        children: [{ id: 50, name: '数据列表', path: '', icon: '' }]
    }
]
const count = menuList.length

module.exports = [
    {
        url: '/api/menu/list',
        type: 'get',
        response: config => {
            const { id, name, path, page = 1, limit = 20, sort } = config.query

            let mockList = menuList.filter(item => {
                /* if (importance && item.importance !== +importance) return false
                if (type && item.type !== type) return false
                if (title && item.title.indexOf(title) < 0) return false */
                return true
            })

            if (sort === '-id') {
                mockList = mockList.reverse()
            }

            const pageList = mockList.filter(
                (item, index) =>
                    index < limit * page && index >= limit * (page - 1)
            )

            return {
                code: 20000,
                data: {
                    total: mockList.length,
                    items: pageList
                }
            }
        }
    },

    {
        url: '/api/menu/detail',
        type: 'get',
        response: config => {
            const { id } = config.query
            for (const article of menuList) {
                if (article.id === +id) {
                    return {
                        code: 20000,
                        data: article
                    }
                }
            }
        }
    },

    {
        url: '/api/menu/pv',
        type: 'get',
        response: _ => {
            return {
                code: 20000,
                data: {
                    pvData: [
                        {
                            key: 'PC',
                            pv: 1024
                        },
                        {
                            key: 'mobile',
                            pv: 1024
                        },
                        {
                            key: 'ios',
                            pv: 1024
                        },
                        {
                            key: 'android',
                            pv: 1024
                        }
                    ]
                }
            }
        }
    },

    {
        url: '/api/menu/create',
        type: 'post',
        response: _ => {
            return {
                code: 20000,
                data: 'success'
            }
        }
    },

    {
        url: '/api/menu/update',
        type: 'post',
        response: _ => {
            return {
                code: 20000,
                data: 'success'
            }
        }
    }
]
